package day_2022_7_to_8.day48;

import java.util.List;
import java.util.Stack;

/**
 * @author haomin
 * @date 2022/08/07 23:22
 **/
public class Day23_6_Num636_ExclusiveTime {
    class Solution {
        public int[] exclusiveTime(int n, List<String> logs) {
            Stack<int[]> stack = new Stack<>();
            int[] res = new int[n];
            for(String log : logs){
                String[] data = log.split(":");
                int id = Integer.parseInt(data[0]);
                int time = Integer.parseInt(data[2]);
                if("start".equals(data[1])){
                    stack.push(new int[]{id, time});
                }else{
                    int[] pop = stack.pop();
                    int hours = time - pop[1] + 1;
                    res[pop[0]] += hours;
                    if(!stack.isEmpty()){
                        res[stack.peek()[0]] -= hours;
                    }
                }
            }
            return res;
        }
    }
}